package cn.edu.java.stream.A创建流;

import java.util.stream.Stream;

public class StreamDemo {
    public static void main(String[] args) {
        // 创建一个包含指定元素的流
        Stream<String> stream = Stream.of("apple", "banana", "orange");

        stream.forEach(System.out::println);


        // 创建一个使用提供的 Supplier 生成的无限流
        Stream<Double> generateStream = Stream.generate(() -> Math.random());

        new Thread(() -> generateStream.forEach(x -> System.out.println(Thread.currentThread().getName() + ": " + x))).start();

        // 创建一个包含迭代生成的元素的无限流
        Stream<Integer> integerStream = Stream.iterate(0, n -> n + 1);

        new Thread(() -> integerStream.forEach(x -> System.out.println(Thread.currentThread().getName() + ": " + x))).start();

    }
}
